package com.wlcj.www.aop;

import java.util.List;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;
import com.wlcj.constant.Global;
import com.wlcj.plugin.NutzPlugin;
import com.wlcj.www.model.main.Channel;
import com.wlcj.www.service.IndexService;

public class IndexInterceptor implements Interceptor {
	
	private IndexService indexService = NutzPlugin.getBean(IndexService.class);

	@Override
	public void intercept(ActionInvocation ai) {
		System.out.println("header拦截器...");
		ai.invoke();
		
		Controller c = ai.getController();
		String requestType = c.getRequest().getHeader("X-Requested-With");
		if(requestType==null) {
			//准备header所需要的数据
			List<Channel> topChannels = indexService.getTopChannels();
			Record ad = indexService.getChannelAd(Global.DATA_CHANNEL_AD_ID);
			c.setAttr("topChannels", topChannels);
			c.setAttr("ad", ad);
		}
		
	}

}
